
# -*- coding: UTF-8 -*-
'''
@Project ：apiautotest 
@File ：locustio.py
@Author ：假斯文
@Params :   
@Date ：2021/7/13 16:16 
'''
from locust import HttpUser,TaskSet,task
import os

class GetResume(TaskSet):

    @task(1)  # 设置权重值，默认为1，值越大，优先执行
    def get_resume(self):
        # 如果后台需要的是json格式，需要加header，否则报415
        header = {"Content-Type": "application/json"}
        self.client.headers.update(header)
        url1 = "/restcloud/hana/query/querysapnxprice"
        json = {
  "data": [
    {
      "itemcode": "90.8092.C000031",
      "businessdate": "2020-11-06",
      "customercode": "PU-603104",
      "issku": "true",
      "orgcode": "1090",
      "pricetype": 1,
      "componentline": [
        {
          "itemcode": "90.8092.1000.C000001",
          "usageqty": 1
        },
        {
          "itemcode": "90.8092.3000.C000001",
          "usageqty": 1
        },
        {
          "itemcode": "90.8092.7007.C000005",
          "usageqty": 1
        },
        {
          "itemcode": "90.8092.9007.C000001",
          "usageqty": 1
        }
      ]
    }
  ]
}
        # 网上是直接把Json的格式填进去，但是在本项目中报400，无法识别数据格式，查看系统报错才明白需要转成json对象
        req = self.client.post(url1, json=json)
        if req.status_code == 200:
            print("success")
        else:
            print("fail")

class websitUser(HttpUser):
    task_set = GetResume
    min_wait = 3000  # 单位为毫秒
    max_wait = 6000  # 单位为毫秒

if __name__ == '__main__':
    os.system('locust -f locustio.py --host=http://192.168.248.32:8888')
